/**
 * 
 */
package com.cipe.cmrs.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cipe.cmrs.model.Fieldoffice;
import com.cipe.cmrs.model.User;
import com.cipe.cmrs.util.DateUtil;
import com.cipe.cmrs.util.UserUtil;

/**
 * @author Incepio
 * 
 */
@Service
@Transactional
public class FieldofficeService extends BaseService<Fieldoffice> {

	@Autowired
	private UserService	userService;

	public Fieldoffice saveFieldoffice(Fieldoffice fieldoffice, Integer userId) {
		if (fieldoffice != null) {
			User user = UserUtil.INSTANCE.getCurrentUser();
			Fieldoffice dbFieldoffice = findById(fieldoffice.getId());
			if (dbFieldoffice == null) {
				dbFieldoffice = new Fieldoffice();
				dbFieldoffice.setCreatedBy(user);
				dbFieldoffice.setCreationDate(DateUtil.getCurrentDate());
			}
			dbFieldoffice.setDisplayName(fieldoffice.getDisplayName());
			dbFieldoffice.setDescription(fieldoffice.getDescription());
			dbFieldoffice.setUpdatedBy(user);
			dbFieldoffice.setUpdationDate(DateUtil.getCurrentDate());
			return merge(dbFieldoffice);
		}
		return null;
	}
}
